import React from 'react'
import './Header.less'
import {withRouter} from "react-router-dom"
// import API from "../../api/common";
import { Modal } from 'antd'
import axios from 'axios'

class Download extends React.Component {
  state = {
    currentUrl: '',
    user_name:  sessionStorage.getItem("user_name")
  }
  modifyPassword = () => {
      this.props.history.push("/passwords/modify")
  }
  logout () {
      axios.get('/Users/logout?token=' + localStorage.getItem("token"))
          .then(res => {
              console.log(res.data)
              if (res.data.error === 0) {
                  sessionStorage.clear()
                  window.location.href = '/login'

              } else {
                  Modal.warning({
                      title: '提示',
                      content: res.msg || '退出失败，请稍后重试',
                  })
              }
          }).catch(error => {
          console.log(error)
      })
  }
  render () {
    return (
      <div className="layer-header">
        <div className='current-user'>当前登录人：{this.state.user_name}</div>
        <div className="current-opr">
          <a className="item" onClick={this.modifyPassword}>修改密码</a>
          <a className="item" onClick={this.logout}>退出</a>
        </div>
      </div>
    )
  }
}
export default withRouter(Download)
